Repository navigation
fix(qwenwork): split tool calls that share an upstream index - #595
Conversation
Signed-off-by: Бат-Орших <34618353+orshih6@users.noreply.github.com>
|
Reviewed against current The change is scoped to the QwenWork SSE adapter. Approving and merging. |
caigee-cmd
left a comment
There was a problem hiding this comment.
Scoped QwenWork fix. Index rewrite only fires when a new tool-call id lands on an already-used index, so distinct-index upstreams are unchanged. Tests cover the reported Qwen4-Max case on both the stream and non-stream paths.
Qwen4-Max on QwenWork CN sends every tool call of a turn at
index: 0and tells them apart only byid. The adapter passed the deltas through unchanged, so OpenAI-style consumers merged them by index. The Responses accumulator, and the adapter's own non-stream merge, ended up with one call namedcli2api_diag_ambercli2api_diag_violetand arguments{"key": "amber"}{"key": "violet"}. The Responses stream then failed with an invalid-JSON error and never sentresponse.completed.This adds a small per-stream
toolCallIndexerininternal/providers/qwenwork/sse.go. It rewrites the index of eachtool_callsdelta before the chunk is relayed (writeOpenAIChunks) or merged (collectUpstream):Tests: two new tests in
client_test.goreplay the reported pattern (two ids sharing index 0, with arguments split across chunks). One runs throughChatNonStream, the other throughChatStreamand folds the relayed deltas by index the way clients do. Both expect two separate calls, at index 0 and 1, each with its own complete arguments. Both fail on main with the merged output from the report and pass with this change.go testpasses for./internal/providers/qwenwork/and./internal/gateway/, andgo vetreports nothing for the qwenwork package.Not included: the report also says a forced
tool_choiceandparallel_tool_callsare not forwarded to QwenWork. I left that out because I can't check which fields the upstream accepts. I also didn't change the gateway's shared Responses accumulator to start a new item when the id changes, because that would affect every provider.🤖 Generated with Claude Code
Fixes #594
This change was prepared with an AI coding agent (Claude) and opened automatically after an automated review, so no person has read it yet. I'm happy to make any changes you'd like.